home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Animated Icons / Source / IconSuitePatches.cp < prev    next >
Text File  |  1997-07-02  |  38KB  |  1,699 lines

  1. #define DONTDEFINEMACROS 1
  2.  
  3. #include "AnimatedIcons.h"
  4. #include "IconSuitePatches.h"
  5. #include "Icons.h"
  6. #include <limits.h>
  7. #include <Traps.h>
  8. #include <LArray.h>
  9. #include <LArrayIterator.h>
  10. #include <A4Stuff.h>
  11. #include <QDOffscreen.h>
  12. #include "LogInterface.h"
  13.  
  14. #ifndef BUILDINGINIT
  15. #include <iostream.h>
  16. #endif
  17.  
  18. UniversalProcPtr gOriginalIconUtilitiesAddr = 0;
  19. UniversalProcPtr gOriginalIconServicesAddr = 0;
  20. UniversalProcPtr gOriginalInitGrafAddr = 0;
  21. UniversalProcPtr gOriginalDisposeWindowTrapAddr = 0;
  22. UniversalProcPtr gOriginalHideWindowTrapAddr = 0;
  23. UniversalProcPtr gOriginalCopybitsAddr = 0;
  24. UniversalProcPtr gOriginalQDUtilitiesAddr = nil;
  25.  
  26. #include <stdarg.h>
  27. #include <stdio.h>
  28.  
  29. LArray* sFinderOffscreenGWorldList = nil;
  30. LogInterfacePtr sLogP = nil;
  31.  
  32. #if 1
  33.  
  34. int     vdprintf( const char * format, va_list arg)
  35. {    
  36.     #if BUILDINGINIT
  37.     Str255 buf;
  38.  
  39.     buf[0] = vsprintf ( (char*) & buf[1], format, arg );
  40.     DebugStr ( buf );
  41.  
  42.     if ( ! sLogP )
  43.         sLogP = GetLogInterfacePtr();
  44.         
  45.     InsertIntoRing ( sLogP, (char*) & buf[1], buf[0] );
  46.     
  47.     #else
  48.  
  49.     vprintf ( format, arg );
  50.     printf ( "\n" );
  51.     #endif
  52. }
  53.  
  54. int    dprintf(const char * format, ...)
  55. {    va_list        args;
  56.  
  57.     va_start(args, format );
  58.  
  59.     int result = vdprintf ( format, args );
  60.  
  61.     va_end ( args );
  62.  
  63.     return result;
  64. }
  65.  
  66. #else
  67.  
  68.  
  69. inline int    dprintf(const char * format, ...) { return 0; };
  70.  
  71. #endif
  72.  
  73. /***********************************|****************************************
  74.  *
  75.  *    Boolean IsOptionKeyDown ( )
  76.  *
  77.  *    Return true if the option key is currently depressed; false otherwise.
  78.  *
  79.  ***********************************|****************************************/
  80. Boolean IsOptionKeyDown ( );
  81. Boolean IsOptionKeyDown ( )
  82. {    KeyMap map;
  83.     const unsigned short optionKeyCode = 0x3a;
  84.     
  85.     GetKeys ( map );
  86.     
  87.     long c = ( ((unsigned char*) &map ) [ optionKeyCode >>  3 ] >> ( optionKeyCode & 7 ) );
  88.         
  89.     return c & 0x01;
  90.     // return ((*(long *)0x178 & 4L) != 0L);
  91. }
  92.  
  93.  
  94. #ifdef BUILDINGINIT
  95.  
  96. OSType gGlobalsCheck = 'KSDC';
  97.  
  98. #define    CheckGlobals()    {    if ( gGlobalsCheck != 'KSDC' ) Debugger(); }
  99.  
  100. //    ============================================================================================
  101.  
  102. void* operator new ( size_t s )
  103. {
  104.     return NewPtrSysClear ( s );
  105. }
  106.  
  107. void operator delete ( void* p )
  108. {
  109.     DisposePtr( (Ptr) p );
  110. }    
  111.  
  112. //    ============================================================================================
  113.  
  114. static asm unsigned long GetA0()
  115. {
  116.     move.l    a0, d0
  117.     rts
  118. }
  119.  
  120. //    ============================================================================================
  121.  
  122. pascal void main ( )
  123. {    
  124.     // Debugger();
  125.  
  126.     Handle ourCodeH = (Handle) GetA0();
  127.  
  128.     SetZone ( SystemZone() );
  129.  
  130.     EnterCodeResource ();
  131.     
  132.     if ( ourCodeH && *ourCodeH && HandleZone( ourCodeH ) == SystemZone() )
  133.     {
  134.         DetachResource ( ourCodeH );
  135.     
  136.         InstallAllUniversalPatches ();
  137.     }
  138.     
  139.     ExitCodeResource ();
  140. }
  141.  
  142. #include "console.stubs.c"
  143.  
  144. #else
  145.  
  146. #define    CheckGlobals()    { }
  147. #endif
  148.  
  149. #if PATCHTRAPS
  150.  
  151. //    ============================================================================================
  152.  
  153. asm pascal OSErr CallGetIconSuite ( Handle *theIconSuite, SInt16 theResID, IconSelectorValue selector )
  154. {
  155.     move.w    #0x0501, d0
  156.     move.l    gOriginalIconUtilitiesAddr, -(sp)
  157.     rts
  158. }
  159.  
  160. asm pascal OSErr CallPlotIconSuite ( const Rect *theRect, IconAlignmentType align, IconTransformType transform, Handle theIconSuite )
  161. {
  162.     move.w    #0x0603, d0
  163.     move.l    gOriginalIconUtilitiesAddr, -(sp)
  164.     rts
  165. }
  166.  
  167. asm pascal OSErr CallDisposeIconSuite ( Handle theIconSuite, Boolean disposeData )
  168. {
  169.     move.w    #0x302, d0
  170.     move.l    gOriginalIconUtilitiesAddr, -(sp)
  171.     rts
  172. }
  173.  
  174. //    ============================================================================================
  175.  
  176. asm pascal OSErr CallGetIconRefFromFile ( const FSSpec *theFile, IconRef *iconRef, SInt16 *theLabel )
  177. {
  178.     move.w    #0x2, d0
  179.     move.l    gOriginalIconServicesAddr, -(sp)
  180.     rts
  181. }
  182.  
  183. asm pascal OSErr CallGetIconRefFromFileInfo ( const FSSpec *theFile, IconRef *iconRef, OSType creator, OSType fileType, Boolean hasCustomIcon )
  184. {
  185.     move.w    #0x3, d0
  186.     move.l    gOriginalIconServicesAddr, -(sp)
  187.     rts
  188. }
  189.  
  190. asm pascal OSErr CallGetIconRefFromFolderInfo ( SInt16 vRefNum, SInt32 folderID, IconRef *iconRef, OSType fileType, Boolean hasCustomIcon )
  191. {
  192.     move.w    #0x4, d0
  193.     move.l    gOriginalIconServicesAddr, -(sp)
  194.     rts
  195. }
  196.  
  197. asm pascal OSErr CallPlotIconRef ( const Rect *theRect, IconAlignmentType align, IconTransformType transform, IconServicesUsageFlags iconServicesUsageFlags, IconRef theIconRef )
  198. {
  199.     move.w    #0xe, d0
  200.     move.l    gOriginalIconServicesAddr, -(sp)
  201.     rts
  202. }
  203.  
  204. asm pascal OSErr CallDisposeIconRef ( IconRef theIconRef )
  205. {
  206.     move.w    #0xd, d0
  207.     move.l    gOriginalIconServicesAddr, -(sp)
  208.     rts
  209. }
  210.  
  211. asm pascal void CallCopyBits ( BitMap* srcBits, BitMap* destBits,
  212.                               const Rect* srcRect, const Rect* destRect,
  213.                               short mode, 
  214.                               RgnHandle maskRgn )
  215. {
  216.     move.l    gOriginalCopybitsAddr, a0
  217.     jmp        (a0)
  218. }
  219.  
  220. asm pascal OSErr CallNewGWorldRoutine ( GWorldPtr *offscreenGWorld, short PixelDepth,
  221.                                const Rect *boundsRect, CTabHandle cTable,
  222.                                GDHandle aGDevice, GWorldFlags flags )
  223. {
  224.     move.l    #0x00160000, d0
  225.     move.l    gOriginalQDUtilitiesAddr, -(sp)
  226.     rts
  227. }                               
  228.  
  229. asm pascal OSErr CallUpdateGWorldRoutine ( GWorldPtr *offscreenGWorld, short PixelDepth,
  230.                                const Rect *boundsRect, CTabHandle cTable,
  231.                                GDHandle aGDevice, GWorldFlags flags )
  232. {
  233.     move.l    #0x00160003, d0
  234.     move.l    gOriginalQDUtilitiesAddr, -(sp)
  235.     rts
  236. }                               
  237.  
  238. asm pascal void CallDisposeGWorld ( GWorldPtr offscreenGWorld )
  239. {
  240.     move.l    #0x00040004, d0
  241.     move.l    gOriginalQDUtilitiesAddr, -(sp)
  242.     rts
  243. }
  244.  
  245. //    ============================================================================================
  246.  
  247. #endif
  248.  
  249. static asm unsigned long GetA4()
  250. {
  251.     move.l    a4, d0
  252.     rts
  253. }
  254.  
  255. static asm unsigned long GetA5()
  256. {
  257.     move.l    a5, d0
  258.     rts
  259. }
  260.  
  261. static UniversalProcPtr PatchTrap ( unsigned short trapNumber, UniversalProcPtr newValue, Boolean keithsSpecialTrapHeader = true )
  262. {    UniversalProcPtr result = GetToolTrapAddress ( trapNumber );
  263.  
  264.     if ( keithsSpecialTrapHeader )
  265.     {
  266.         char* patchRoutine = (char*) newValue;
  267.  
  268.         * ( UniversalProcPtr *) ( ( patchRoutine ) + 2 ) = result;
  269.  
  270.         #ifdef BUILDINGINIT
  271.         * ( unsigned long *) ( ( patchRoutine ) + 6 ) = GetA4();
  272.         #else
  273.         * ( unsigned long *) ( ( patchRoutine ) + 6 ) = GetA5();
  274.         #endif
  275.     }
  276.     
  277.     SetToolTrapAddress ( (UniversalProcPtr) newValue, trapNumber );
  278.     
  279.     return result;
  280. }
  281.  
  282. pascal void InstallGNEFilter ( )
  283. {
  284.     #ifdef BUILDINGINIT
  285.     static Boolean installed = false;
  286.  
  287.     if ( ! installed )
  288.     {    GNEFilterUPP originalGNEFilterProc = LMGetGNEFilter();
  289.             
  290.         char* patchRoutine = (char*) jGNEFilter;
  291.         
  292.         * ( UniversalProcPtr *) ( ( patchRoutine ) + 2 ) = (UniversalProcPtr) originalGNEFilterProc;
  293.  
  294.         #ifdef BUILDINGINIT
  295.         * ( unsigned long *) ( ( patchRoutine ) + 6 ) = GetA4();
  296.         #else
  297.         * ( unsigned long *) ( ( patchRoutine ) + 6 ) = GetA5();
  298.         #endif
  299.  
  300.         LMSetGNEFilter ( (GNEFilterUPP) jGNEFilter );
  301.  
  302.         installed = true;
  303.     }
  304.     #endif
  305. }
  306.  
  307. pascal void InstallAllUniversalPatches ( )
  308. {
  309.     InstallIconUtilitiesPatches ();
  310.     InstallDisposeWindowPatch ();
  311.     
  312.     #ifdef BUILDINGINIT
  313.     InstallGNEFilter();
  314.     #endif
  315. }
  316.  
  317. pascal void InstallIconUtilitiesPatches ( )
  318. {    
  319.     #if PATCHTRAPS
  320.     static Boolean installed = false;
  321.  
  322.     if ( ! installed )
  323.     {
  324.         installed = true;
  325.         
  326.         gOriginalIconUtilitiesAddr = PatchTrap ( _IconDispatch, (UniversalProcPtr) & IconUtilitiesTrapPatch );
  327.         gOriginalInitGrafAddr = PatchTrap ( _InitGraf, (UniversalProcPtr) & InitGrafPatch );
  328.     }
  329.     #endif
  330.     
  331.     if ( ! gIconsToAnimate )
  332.         gIconsToAnimate = new LArray ( sizeof( void*) );
  333.     if ( ! gIconsOnScreen )
  334.         gIconsOnScreen = new LArray ( sizeof( void*) );    
  335.     if ( ! sFinderOffscreenGWorldList )
  336.         sFinderOffscreenGWorldList = new LArray ( sizeof( void*) );
  337. }
  338.  
  339. pascal void InstallIconServicesPatches ( )
  340. {
  341.     #if PATCHTRAPS
  342.     static Boolean installed = false;
  343.     const unsigned short _IconServicesTrap = 0xaa75;
  344.     
  345.     if ( ! installed )
  346.     {
  347.         installed = true;
  348.         
  349.         gOriginalIconServicesAddr = PatchTrap ( _IconServicesTrap, (UniversalProcPtr) & IconServicesTrapPatch );
  350.     }
  351.     #endif
  352. }
  353.  
  354. pascal void InstallDisposeWindowPatch ( )
  355. {
  356.     #if PATCHTRAPS
  357.     static Boolean installed = false;
  358.     
  359.     if ( ! installed )
  360.     {
  361.         installed = true;
  362.         
  363.         gOriginalDisposeWindowTrapAddr = PatchTrap ( _DisposeWindow, (UniversalProcPtr) & DisposeWindowPatch );
  364.         gOriginalHideWindowTrapAddr = PatchTrap ( _DisposeWindow, (UniversalProcPtr) & HideWindowPatch );
  365.     }
  366.     #endif
  367. }
  368.  
  369. pascal void InstallCopyBitsPatch ( )
  370. {
  371.     #if PATCHTRAPS
  372.     static Boolean installed = false;
  373.     
  374.     if ( ! installed )
  375.     {
  376.         installed = true;
  377.         
  378.         gOriginalCopybitsAddr = PatchTrap ( _CopyBits, (UniversalProcPtr) & CopyBitsPatch, true );
  379.         gOriginalQDUtilitiesAddr = PatchTrap ( _QDExtensions, (UniversalProcPtr) & QDExtensionsPatch, true );
  380.     }
  381.     #endif
  382. }
  383.  
  384.  
  385. class StUseSystemHeap
  386. {
  387. public:                        StUseSystemHeap ( ) { mSavedZone = GetZone(); SetZone ( SystemZone() ); };
  388.                             ~StUseSystemHeap ( ) { if ( mSavedZone ) SetZone( mSavedZone ); };
  389.  
  390.     void                    RestoreHeap ( ) { SetZone ( mSavedZone ); mSavedZone = nil; };
  391.                             
  392. protected:
  393.     THz            mSavedZone;
  394. };
  395.  
  396.  
  397. pascal OSErr NewIconSuiteFromFilePatch (const FSSpec *spec, IconSelectorValue whichIcons, Handle *iconSuite, IconServicesUsageFlags iconServicesUsageFlags)
  398. {
  399.     short savedCurResFile = CurResFile();
  400.     Handle originalTopMapH = LMGetTopMapHndl ();
  401.     
  402.     short resFileRefNum = FSpOpenResFile ( spec, fsRdPerm );
  403.     OSErr result = ResError();
  404.     
  405.     if ( result == noErr )
  406.     {
  407.         Handle newTopMapH = LMGetTopMapHndl();
  408.         Boolean closeResFileAfterWeAreDone  = ( originalTopMapH != newTopMapH );
  409.     
  410.         result = GetIconSuite ( iconSuite, kCustomIconResource, whichIcons ); 
  411.  
  412.         if ( resFileRefNum && closeResFileAfterWeAreDone )
  413.             CloseResFile ( resFileRefNum );
  414.     }
  415.     
  416.     UseResFile ( savedCurResFile );
  417.     
  418.     return result;
  419. }
  420.  
  421. //    ============================================================================================
  422.  
  423. static pascal OSErr GetIconSuiteAndRefCommon ( const void* theIconRef, FSSpec* spec, short resFileRefNum, short theResID )
  424. {    StUseSystemHeap saveZone;
  425.     short savedResFile = CurResFile();
  426.     
  427.     UseResFile ( resFileRefNum );
  428.     
  429.     Handle h = Get1Resource ( 'AICN', theResID );
  430.     if ( h && *h )
  431.     {
  432.         AnimatedIcon* a = new FrameAnimatedIcon ( theIconRef, (FrameAnimatedIcon::FrameAnimatedIconResourceHandle) h );
  433.         ReleaseResource ( h );
  434.         
  435.         dprintf ( "Frame: %lx -> %lx", (void*) theIconRef, a );
  436.     }
  437.     else if ( ( h = Get1Resource ( 'MICN', theResID ) ) && *h && QuicktimeMovieAnimatedIcon::IsQuicktimeAvailable() )
  438.     {
  439.         QuicktimeMovieAnimatedIcon* movieAnimation = new QuicktimeMovieAnimatedIcon ( theIconRef, (QuicktimeMovieAnimatedIcon::QuicktimeMovieAnimatedIconResourceHandle) h, spec, 0 );
  440.         ReleaseResource ( h );
  441.  
  442.         dprintf ( "Quicktime: %lx -> %lx", (void*) theIconRef, movieAnimation );
  443.     }
  444.     else if ( ( h = Get1Resource ( 'PICN', theResID ) ) && *h )
  445.     {
  446.         PictureAnimatedIcon* pictureAnimation = new PictureAnimatedIcon ( theIconRef, (PictureAnimatedIcon::PictureAnimatedIconResourceHandle) h );
  447.         ReleaseResource ( h );    
  448.  
  449.         dprintf ( "Picture: %lx -> %lx", (void*) theIconRef, pictureAnimation );
  450.     }
  451.     else if ( ( h = Get1Resource ( 'ßICN', theResID ) ) && *h )
  452.     {
  453.         SoundAnimatedIcon* pictureAnimation = new SoundAnimatedIcon ( theIconRef, (SoundAnimatedIcon::SoundAnimatedIconResourceHandle) h );
  454.         ReleaseResource ( h );    
  455.     }
  456.     else if ( ( h = Get1Resource ( 'VICN', theResID ) ) && *h )
  457.     {
  458.         VoiceAnimatedIcon* pictureAnimation = new VoiceAnimatedIcon ( theIconRef, (VoiceAnimatedIcon::VoiceAnimatedIconResourceHandle) h, spec );
  459.         ReleaseResource ( h );    
  460.     }
  461.     
  462.     UseResFile ( savedResFile );
  463.     return noErr;
  464. }
  465.  
  466. //    ============================================================================================
  467.  
  468. pascal OSErr GetIconSuitePatch (Handle *theIconSuite, SInt16 theResID, IconSelectorValue selector)
  469. {    
  470.     CheckGlobals();
  471.     
  472.     OSErr result = CallGetIconSuite ( theIconSuite, theResID, selector );
  473.     if ( result == noErr )
  474.         result = GetIconSuiteAndRefCommon ( *theIconSuite, nil, CurResFile(), theResID ); 
  475.     
  476.     return result;
  477. }
  478.  
  479. //    ============================================================================================
  480.  
  481. static pascal OSErr GetIconRefCommon (  const FSSpec* spec, IconRef *theIconRef, short theResID )
  482. {    StUseSystemHeap saveZone;
  483.  
  484.     short savedCurResFile = CurResFile();
  485.     Handle originalTopMapH = LMGetTopMapHndl ();
  486.     
  487.     short resFileRefNum = FSpOpenResFile ( spec, fsRdPerm );
  488.     OSErr result = ResError();
  489.     
  490.     if ( result == noErr )
  491.     {
  492.         Handle newTopMapH = LMGetTopMapHndl();
  493.         Boolean closeResFileAfterWeAreDone  = ( originalTopMapH != newTopMapH );
  494.     
  495.         result = GetIconSuiteAndRefCommon ( *theIconRef, spec, CurResFile(), theResID ); 
  496.  
  497.         if ( resFileRefNum && closeResFileAfterWeAreDone )
  498.             CloseResFile ( resFileRefNum );
  499.     }
  500.     
  501.     UseResFile ( savedCurResFile );
  502.     
  503.     return noErr;
  504. }
  505.  
  506. //    ============================================================================================
  507.  
  508. pascal OSErr GetIconRefFromFilePatch ( const FSSpec* spec, IconRef *theIconRef, SInt16* label )
  509. {    
  510.     CheckGlobals();
  511.     
  512.     OSErr result = CallGetIconRefFromFile ( spec, theIconRef, label );
  513.     if ( result == noErr )
  514.         result = GetIconRefCommon ( spec, theIconRef, kCustomIconResource );
  515.     
  516.     return result;
  517. }
  518.  
  519. pascal OSErr GetIconRefFromFileInfoPatch ( const FSSpec *spec, IconRef *iconRef, OSType creatorCode, OSType fileType, Boolean hasCustomIcon )
  520. {    
  521.     CheckGlobals();
  522.     
  523.     OSErr result = CallGetIconRefFromFileInfo ( spec, iconRef, creatorCode, fileType, hasCustomIcon );
  524.  
  525.     if ( result == noErr && hasCustomIcon )
  526.         result = GetIconRefCommon ( spec, iconRef, kCustomIconResource );
  527.     
  528.     return result;
  529. }
  530.  
  531. extern pascal OSErr GetIconRefFromFolderInfoPatch (SInt16 vRefNum, SInt32 folderID, IconRef *iconRef, OSType fileType, Boolean hasCustomIcon)
  532. {    
  533.     CheckGlobals();
  534.     
  535.     OSErr result = CallGetIconRefFromFolderInfo ( vRefNum, folderID, iconRef, fileType, hasCustomIcon );
  536.  
  537.     if ( result == noErr && hasCustomIcon )
  538.     {    FSSpec spec;
  539.     
  540.         result = FSMakeFSSpec ( vRefNum, folderID, "\pIcon\r", & spec );
  541.         if ( result == noErr )
  542.             result = GetIconRefCommon ( & spec, iconRef, kCustomIconResource );
  543.     }
  544.     
  545.     return result;
  546. }
  547.  
  548. //    ============================================================================================
  549.  
  550. pascal OSErr PlotIconSuitePatch (const Rect *theRect, IconAlignmentType align, IconTransformType transform, Handle theIconSuite)
  551. {    StUseSystemHeap saveZone;
  552.     OSErr result = noErr;
  553.     
  554.     CheckGlobals();
  555.  
  556.     GrafPtr currentPort;
  557.     GetPort ( & currentPort );
  558.     
  559.     AnimatedIconOnScreen* a = AnimatedIconOnScreen::GetAnimatedIconOnScreen ( currentPort, *theRect, theIconSuite );
  560.     AnimatedIcon* animatedIcon = nil;
  561.     if ( ! a )
  562.     {
  563.         animatedIcon = AnimatedIcon::GetAnimatedIconForIconSuite ( theIconSuite );
  564.  
  565.         if ( animatedIcon )
  566.         {
  567.             a = animatedIcon->GetNewAnimatedIconOnScreen( currentPort, theRect, align, transform );
  568.         }
  569.         
  570.         gNextTickToCheckAnimations = 0;
  571.     }
  572.  
  573.     if ( a && transform == ttNone )
  574.         result = a->Draw( theRect, align, transform );
  575.     else
  576.         result = errForceCallToOriginalPlotIcon;
  577.         
  578.     if ( result == errForceCallToOriginalPlotIcon )
  579.     {
  580.         saveZone.RestoreHeap ();
  581.         result = ::CallPlotIconSuite ( theRect, align, transform, theIconSuite );
  582.     }
  583.  
  584.     SetPort ( currentPort );
  585.  
  586.     return result;
  587. }
  588.  
  589. pascal OSErr PlotIconRefPatch (const Rect *theRect, IconAlignmentType align, IconTransformType transform, IconServicesUsageFlags iconServicesUsageFlags, IconRef iconRef )
  590. {    OSErr result = noErr;
  591.     
  592.     CheckGlobals();
  593.     
  594.     StUseSystemHeap saveZone;
  595.         
  596.     GrafPtr currentPort;
  597.     GetPort ( & currentPort );
  598.     
  599.     AnimatedIconOnScreen* a = AnimatedIconOnScreen::GetAnimatedIconOnScreen ( currentPort, *theRect, iconRef );
  600.     AnimatedIcon* animatedIcon = nil;
  601.     if ( ! a )
  602.     {        
  603.         animatedIcon = AnimatedIcon::GetAnimatedIconForIconSuite ( iconRef );
  604.  
  605.         if ( animatedIcon )
  606.         {
  607.             a = animatedIcon->GetNewAnimatedIconOnScreen( currentPort, theRect, align, transform );
  608.             dprintf ( "Making new animIcon %lx for ref=%lx", a, iconRef );
  609.         }
  610.         
  611.         gNextTickToCheckAnimations = 0;
  612.     }
  613.  
  614.     if ( a )
  615.         dprintf ( "PlotIconRef: subst %lx trans=%d port %lx", a, transform, a->GetPort() );
  616.  
  617.     if ( a && ( ( transform == ttNone ) || ( transform == ttSelected ) ) )
  618.     {
  619.         result = a->Draw( theRect, align, transform );
  620.     }
  621.     else
  622.         result = errForceCallToOriginalPlotIcon;
  623.         
  624.     if ( result == errForceCallToOriginalPlotIcon )
  625.     {
  626.         saveZone.RestoreHeap();
  627.         result = ::CallPlotIconRef ( theRect, align, transform, iconServicesUsageFlags, iconRef );
  628.     }
  629.  
  630.     return result;
  631. }
  632.  
  633. //    ============================================================================================
  634.  
  635. pascal OSErr DisposeIconSuitePatch (Handle theIconSuite, Boolean disposeData)
  636. {    
  637.     CheckGlobals();
  638.  
  639.     AnimatedIcon* a = AnimatedIcon::GetAnimatedIconForIconSuite ( theIconSuite );
  640.  
  641.     if ( a )
  642.     {    StUseSystemHeap saveZone;
  643.  
  644.         AnimatedIconOnScreen* animatedIcon = nil;
  645.         for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIcon ); )
  646.             if ( animatedIcon && animatedIcon->GetAnimatedIcon() == a )
  647.                 delete animatedIcon;
  648.  
  649.         delete a;
  650.     }
  651.  
  652.     OSErr result = CallDisposeIconSuite ( theIconSuite, disposeData );
  653.  
  654.     return result;
  655. }
  656.  
  657. pascal OSErr DisposeIconRefPatch ( IconRef iconRef )
  658. {    StUseSystemHeap saveZone;
  659.  
  660.     CheckGlobals();
  661.  
  662.     dprintf ( "DisposeIconRefCommon, icon=%lx", iconRef );
  663.     
  664.     if ( iconRef )
  665.     {    StUseSystemHeap saveZone;
  666.  
  667.         AnimatedIcon* a = AnimatedIcon::GetAnimatedIconForIconSuite ( iconRef );
  668.  
  669.         if ( a  )
  670.         {    
  671.             AnimatedIconOnScreen* animatedIcon = nil;
  672.             for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIcon ); )
  673.                 if ( animatedIcon && animatedIcon->GetAnimatedIcon() == a )
  674.                     delete animatedIcon;
  675.  
  676.             delete a;
  677.         }
  678.     }
  679.  
  680.     OSErr result = CallDisposeIconRef ( iconRef );
  681.  
  682.     return result;
  683. }
  684.  
  685. //    ============================================================================================
  686.  
  687. static WindowPeek    FindWindowInWindowList ( GrafPtr windowToFindP )
  688. {    WindowPeek result = nil;
  689.  
  690.     for ( WindowPeek windowP = (WindowPeek) FrontWindow(); windowP; windowP = windowP->nextWindow )
  691.     {
  692.         if ( (WindowPtr) windowP == (WindowPtr) windowToFindP )
  693.         {
  694.             result = windowP;
  695.             break;
  696.         }
  697.     }
  698.  
  699.     return result;
  700. }
  701.  
  702. //    ============================================================================================
  703.  
  704. static GrafPtr    FindWindowForBitMap ( BitMap* bitMap )
  705. {    GrafPtr result = nil;
  706.  
  707.     for ( WindowPeek windowP = (WindowPeek) FrontWindow(); windowP; windowP = windowP->nextWindow )
  708.     {
  709.         if ( windowP->port.portBits.rowBytes & 0x8000 )
  710.         {
  711.             if ( ( & windowP->port.portBits == bitMap ) )
  712.             {
  713.                 result = (GrafPtr) windowP;
  714.                 break;
  715.             }
  716.         }
  717.         else if ( windowP->port.portBits.baseAddr == bitMap->baseAddr )
  718.         {
  719.             result = (GrafPtr) windowP;
  720.             break;
  721.         }
  722.     }
  723.  
  724.     return result;
  725. }
  726.  
  727. //    ============================================================================================
  728.  
  729. static unsigned long InvalidateCurrentIcons ( Boolean drawIconsAsWell = true )
  730. {    AnimatedIconOnScreen* animatedIcon = nil;
  731.     GrafPtr savedPort;
  732.     
  733.     static unsigned long nextInvalidateTick = 0;
  734.     
  735.     unsigned long result = ULONG_MAX;
  736.     
  737.     GetPort ( & savedPort );
  738.     
  739.     unsigned long now = TickCount();
  740.     
  741.     Boolean invalidateIconsAsWell = ( nextInvalidateTick < TickCount() );
  742.     
  743.     for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIcon ); )
  744.     {    
  745.         dprintf ( "Inval: %lx port:%lx ", animatedIcon, (void*) animatedIcon->GetPort() );
  746.  
  747.         if ( animatedIcon && animatedIcon->GetNextAnimationTick() <= now)
  748.         {
  749.             if ( ! FindWindowInWindowList ( animatedIcon->GetPort() ) )
  750.                 continue;
  751.  
  752.             SetPort ( animatedIcon->GetPort() );
  753.  
  754.             animatedIcon->Advance();
  755.  
  756.             if ( ! drawIconsAsWell || invalidateIconsAsWell )
  757.             {
  758.                 InvalRect ( & animatedIcon->GetRect() );
  759.                 animatedIcon->IncrementCountOfTimesThisHasBeenInvalidated();
  760.             }
  761.             
  762.             animatedIcon->Idle();
  763.             
  764.             if ( animatedIcon->GetNextAnimationTick() < result )
  765.                 result = animatedIcon->GetNextAnimationTick();
  766.             
  767.             if ( animatedIcon->GetCountOfTimesThisHasBeenInvalidated() > 6 )
  768.                 delete animatedIcon;
  769.         }
  770.     }
  771.     
  772.     if ( invalidateIconsAsWell )
  773.     nextInvalidateTick = TickCount() + 30;
  774.     
  775.     SetPort ( savedPort );
  776.     
  777.     return result;
  778. }
  779.  
  780. static pascal void DisposeWindowRoutine ( WindowPtr windowP )
  781. {    AnimatedIconOnScreen* animatedIcon = nil;
  782.  
  783.     CheckGlobals();
  784.  
  785.     for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIcon ); )
  786.     {
  787.         if ( animatedIcon && animatedIcon->GetPort() == windowP )
  788.             delete animatedIcon;
  789.     }
  790. }
  791.  
  792. static pascal void CopyBitsRoutine ( BitMap* srcBits, BitMap* destBits,
  793.                               const Rect* srcRect, const Rect* destRect,
  794.                               short mode, RgnHandle maskRgn )
  795. {    AnimatedIconOnScreen* animatedIcon = nil;
  796.     RgnHandle maskRgnMinusIconsWeAreMirroring = nil;
  797.     
  798.     Debugger ();
  799.         
  800.     if ( srcBits != destBits )
  801.     {    WindowPtr destWindow = nil;
  802.         GWorldPtr offscreenGWorld = nil;
  803.         
  804.         for ( LArrayIterator iter ( *sFinderOffscreenGWorldList ); iter.Next( & offscreenGWorld ); )
  805.         {
  806.             dprintf ( "CopyBits1: offscreenGWorld=%x bits=%x srcBits=%x",
  807.                         offscreenGWorld, & offscreenGWorld->portPixMap, srcBits );
  808.                             
  809.             if ( offscreenGWorld && offscreenGWorld->portPixMap && *offscreenGWorld->portPixMap &&
  810.                         (void*) & ** offscreenGWorld->portPixMap == (void*) srcBits )
  811.             {
  812.                 if ( destWindow == nil )
  813.                 {
  814.                     destWindow = FindWindowForBitMap ( destBits );
  815.                     if ( ! destWindow )
  816.                         break;
  817.                 }
  818.  
  819.                 dprintf ( "CopyBits2: Move icon=%x from port=%x to port %x",
  820.                             animatedIcon, offscreenGWorld, destWindow );
  821.             
  822.                 if ( destWindow )
  823.                     animatedIcon->SetPort ( destWindow );
  824.             }
  825.         }
  826.         
  827.         for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIcon ); )
  828.         {
  829.             //    Otherwise, if the destination for this copybits is the same port as this icon,
  830.             //    then subtract the region we're mirroring this icon from the mask for the
  831.             //    copybits.  This keeps the Finder from overwriting our icons on the screen 
  832.             if ( animatedIcon && animatedIcon->GetPort()->portBits.baseAddr == destBits->baseAddr )
  833.             {
  834.                 dprintf ( "CopyBits: Subtracting this icon from port=%x rect=%d %d %d %d",
  835.                             animatedIcon, animatedIcon->GetRect().top, animatedIcon->GetRect().left, animatedIcon->GetRect().bottom, animatedIcon->GetRect().right );
  836.  
  837.                 if ( ! maskRgnMinusIconsWeAreMirroring )
  838.                 {
  839.                     maskRgnMinusIconsWeAreMirroring = NewRgn();
  840.                     if ( maskRgnMinusIconsWeAreMirroring )
  841.                         CopyRgn ( maskRgn, maskRgnMinusIconsWeAreMirroring );
  842.                 }
  843.                 
  844.                 if ( maskRgnMinusIconsWeAreMirroring )
  845.                     DiffRgn ( maskRgnMinusIconsWeAreMirroring, animatedIcon->GetRgn(), maskRgnMinusIconsWeAreMirroring );
  846.             }
  847.         }
  848.     }
  849.  
  850.     if ( srcBits == destBits && mode == srcCopy )
  851.     {    
  852.         for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIcon ); )
  853.         {    short    deltaH = srcRect->left - destRect->left;
  854.             short deltaV = srcRect->top - destRect->top;
  855.             
  856.             if ( animatedIcon && ( & animatedIcon->GetPort()->portBits == srcBits ) )
  857.             {    Rect ourIconRect = animatedIcon->GetRect();
  858.                 Rect intersectionRect;
  859.                 
  860.                 if ( SectRect ( srcRect, & ourIconRect, & intersectionRect ) )
  861.                 {
  862.                     OffsetRect ( & ourIconRect, - deltaH, - deltaV );
  863.                 
  864.                     animatedIcon->SetRect ( ourIconRect );
  865.                 }
  866.             }
  867.         }
  868.     }
  869.     
  870.     if ( maskRgnMinusIconsWeAreMirroring )
  871.         maskRgn = maskRgnMinusIconsWeAreMirroring;
  872.  
  873.     CallCopyBits ( srcBits, destBits,srcRect, destRect, mode, maskRgn );
  874.  
  875.     if ( maskRgnMinusIconsWeAreMirroring )
  876.         DisposeRgn ( maskRgnMinusIconsWeAreMirroring );
  877. }
  878.  
  879. static Boolean DoesRectMatchOnOnScreenWindow ( const Rect* r )
  880. {    Boolean result = false;
  881.  
  882.     for ( WindowPeek windowP = (WindowPeek) FrontWindow(); windowP; windowP = (WindowPeek) windowP->nextWindow )
  883.     {
  884.         if ( EqualRect ( & ((WindowPtr) windowP)->portRect, r ) )
  885.         {
  886.             result = true;
  887.             break;
  888.         }
  889.     }
  890.  
  891.     return result;
  892. }
  893.  
  894. static pascal QDErr NewGWorldRoutine (GWorldPtr *offscreenGWorld, short PixelDepth,
  895.                            const Rect *boundsRect, CTabHandle cTable,
  896.                            GDHandle aGDevice, GWorldFlags flags)
  897. {    OSErr err = CallNewGWorldRoutine ( offscreenGWorld, PixelDepth, boundsRect, cTable, aGDevice, flags );
  898.  
  899.     if ( DoesRectMatchOnOnScreenWindow ( boundsRect ) )
  900.     {
  901.         dprintf ( "NewGWorldRoutine(), add %x to gWorld list", offscreenGWorld );
  902.         
  903.         sFinderOffscreenGWorldList->InsertItemsAt ( 1, LArray::index_Last, & *offscreenGWorld, sizeof( *offscreenGWorld ) );
  904.     }
  905.             
  906.     return err;
  907. }
  908.  
  909. static pascal QDErr UpdateGWorldRoutine (GWorldPtr *offscreenGWorld, short PixelDepth,
  910.                            const Rect *boundsRect, CTabHandle cTable,
  911.                            GDHandle aGDevice, GWorldFlags flags)
  912. {    OSErr err = CallUpdateGWorldRoutine ( offscreenGWorld, PixelDepth, boundsRect, cTable, aGDevice, flags );
  913.             
  914.     return err;
  915. }
  916.  
  917. static pascal void DisposeGWorldRoutine ( GWorldPtr offscreenGWorld )
  918. {    
  919.     if ( sFinderOffscreenGWorldList )
  920.     {
  921.         dprintf ( "DisposeGWorldRoutine(), removing %x to gWorld list", offscreenGWorld );
  922.  
  923.         sFinderOffscreenGWorldList->Remove ( & offscreenGWorld, sizeof( offscreenGWorld ) );
  924.     }
  925.         
  926.     CallDisposeGWorld ( offscreenGWorld );
  927. }
  928.  
  929. static Boolean FinderIsActiveApp ( )
  930. {    Boolean result = false;
  931.     StringPtr appName = LMGetCurApName();
  932.     
  933.     if ( appName[0] == 6 && appName[1] == 'F' && appName[2] == 'i' &&
  934.             appName[3] == 'n' && appName[4] == 'd' && appName[5] == 'e' &&
  935.             appName[6] == 'r' )
  936.     {
  937.         result = true;
  938.     }
  939.     
  940.     return result;
  941. }
  942.  
  943. pascal Boolean MyGNEFilterRoutine ( EventRecord* event )
  944. {    StUseSystemHeap saveZone;
  945.     Boolean result = true;
  946.  
  947.     if ( event->what == nullEvent && gNextTickToCheckAnimations <= TickCount() && FinderIsActiveApp() )
  948.     {
  949.         gNextTickToCheckAnimations = InvalidateCurrentIcons ( );
  950.     }
  951.     
  952.     #ifndef BUILDINGINIT
  953.     if ( IsOptionKeyDown() )
  954.     {
  955.         cout << "Icon suites & icon refs being replace:" << (*gIconsToAnimate).GetCount() << endl;
  956.         AnimatedIcon* animatedIcon = nil;
  957.         for ( LArrayIterator iter ( *gIconsToAnimate ); iter.Next( & animatedIcon ); )
  958.         {
  959.             cout << " " << (void*) animatedIcon << " Replaces:" << animatedIcon->GetIconSuiteThisReplaces() << endl;
  960.         }
  961.  
  962.         cout << "Icons on Screen:" << (*gIconsToAnimate).GetCount() << endl;
  963.         AnimatedIconOnScreen* animatedIconOnScreen = nil;
  964.         for ( LArrayIterator iter ( *gIconsOnScreen ); iter.Next( & animatedIconOnScreen ); )
  965.         {
  966.             cout << " Grafport:" << animatedIconOnScreen->GetPort() <<
  967.                     " Rect" << animatedIconOnScreen->GetRect().top << "," << animatedIconOnScreen->GetRect().left << "-" <<
  968.                         animatedIconOnScreen->GetRect().bottom << ", " << animatedIconOnScreen->GetRect().right << 
  969.                     " nextTick:" << animatedIconOnScreen->GetNextAnimationTick() - TickCount() <<
  970.                     endl;
  971.         }
  972.     }
  973.     #endif
  974.     
  975.     return result;
  976. }
  977.  
  978. #define    registersToSave    a1-a5/d1-d7
  979.  
  980. pascal asm OSErr IconUtilitiesTrapPatch ()
  981. {
  982.     bra.s    @start
  983.  
  984. originalPatchAddress:    
  985.     dc.l    0
  986.     
  987. myGlobals:
  988.     dc.l    0    
  989.  
  990. @start:    
  991.  
  992.     cmp.w    #0x0501, d0
  993.     beq.s    @GetIconSuiteDispatch
  994.     
  995.     cmp.w    #0x0603, d0
  996.     beq.s    @PlotIconSuiteDispatch
  997.  
  998.     cmp.w    #0x302, d0
  999.     beq        @DisposeIconSuiteDispatch
  1000.  
  1001.     move.l    originalPatchAddress, -(sp)
  1002.     
  1003.     rts
  1004.  
  1005. //    pascal OSErr GetIconSuite ( Handle *theIconSuite, SInt16 theResID, IconSelectorValue selector );
  1006. //
  1007. @GetIconSuiteDispatch:    
  1008.     // _Debugger
  1009.     
  1010.     link    a6, #0
  1011.     movem.l    registersToSave, -(sp)
  1012.  
  1013.     #ifdef BUILDINGINIT
  1014.     move.l    myGlobals, a4
  1015.     #else
  1016.     move.l    myGlobals, a5
  1017.     #endif
  1018.  
  1019.     clr.w    -(sp)    
  1020.     move.l    14(a6), -(sp)
  1021.     move.w    12(a6), -(sp)
  1022.     move.l     8(a6), -(sp)
  1023.     
  1024.     jsr        GetIconSuitePatch
  1025.  
  1026.     move.w    (sp)+, d0    
  1027.     movem.l    (sp)+, registersToSave
  1028.     
  1029.     unlk    a6
  1030.     
  1031.     move.l    (sp)+, a0
  1032.     add.l    #10, sp
  1033.     move.w    d0, (sp)
  1034.     
  1035.     jmp        (a0)
  1036.  
  1037. //    pascal OSErr PlotIconSuite (const Rect *theRect, IconAlignmentType align,
  1038. //                                IconTransformType transform, Handle theIconSuite)
  1039. //
  1040. //        4    return addr
  1041. //        8    theIconSuite
  1042. //        12    transform
  1043. //        14    align
  1044. //        16    theRect
  1045. //        20    result
  1046. //
  1047. @PlotIconSuiteDispatch:
  1048.  
  1049.     // _Debugger
  1050.  
  1051.     link    a6, #0
  1052.     movem.l    registersToSave, -(sp)
  1053.  
  1054.     #ifdef BUILDINGINIT
  1055.     move.l    myGlobals, a4
  1056.     #else
  1057.     move.l    myGlobals, a5
  1058.     #endif
  1059.     
  1060.     clr.w    -(sp)                // space for result
  1061.     move.l    16(a6), -(sp)        
  1062.     move.w    14(a6), -(sp)
  1063.     move.w    12(a6), -(sp)
  1064.     move.l     8(a6), -(sp)
  1065.  
  1066.     jsr        PlotIconSuitePatch
  1067.  
  1068.     move.w    (sp)+, d0    
  1069.     movem.l    (sp)+, registersToSave
  1070.     
  1071.     unlk    a6
  1072.     
  1073.     move.l    (sp)+, a0
  1074.     add.l    #12, sp
  1075.     move.w    d0, (sp)
  1076.     
  1077.     jmp        (a0)
  1078.  
  1079.  
  1080. #if 0
  1081. @PlotIconSuiteMethodDispatch:
  1082.  
  1083.     // _Debugger
  1084.  
  1085.     link    a6, #0
  1086.     movem.l    registersToSave, -(sp)
  1087.  
  1088.     #ifdef BUILDINGINIT
  1089.     move.l    myGlobals, a4
  1090.     #else
  1091.     move.l    myGlobals, a5
  1092.     #endif
  1093.  
  1094.     clr.w    -(sp)                // space for result
  1095.     move.l    20(a6), -(sp)
  1096.     move.w    18(a6), -(sp)
  1097.     move.w    16(a6), -(sp)
  1098.     move.w    12(a6), -(sp)
  1099.     move.l     8(a6), -(sp)
  1100.     
  1101.     jsr        PlotIconSuiteMethodPatch
  1102.  
  1103.     move.w    (sp)+, d0    
  1104.     movem.l    (sp)+, registersToSave
  1105.     
  1106.     unlk    a6
  1107.     
  1108.     move.l    (sp)+, a0
  1109.     add.l    #12, sp
  1110.     move.w    d0, (sp)
  1111.     
  1112.     jmp        (a0)
  1113. #endif
  1114.     
  1115. @DisposeIconSuiteDispatch:
  1116.  
  1117.     // _Debugger
  1118.     
  1119.     link    a6, #0
  1120.     movem.l    registersToSave, -(sp)
  1121.  
  1122.     #ifdef BUILDINGINIT
  1123.     move.l    myGlobals, a4
  1124.     #else
  1125.     move.l    myGlobals, a5
  1126.     #endif
  1127.  
  1128.     clr.w    -(sp)                // space for result
  1129.     move.l    10(a6), -(sp)        //    Boolean: disposeIcons
  1130.     move.w     8(a6), -(sp)        //    Handle: iconSuiteH
  1131.     
  1132.     jsr        DisposeIconSuitePatch
  1133.  
  1134.     move.w    (sp)+, d0    
  1135.     movem.l    (sp)+, registersToSave
  1136.     
  1137.     unlk    a6
  1138.     
  1139.     move.l    (sp)+, a0
  1140.     add.l    #6, sp
  1141.     move.w    d0, (sp)
  1142.     
  1143.     jmp        (a0)
  1144. }
  1145.  
  1146. pascal asm void InitGrafPatch ( GrafPtr )
  1147. {
  1148.     bra.s    @start
  1149.  
  1150. originalPatchAddress:    
  1151.     dc.l    0
  1152.     
  1153. myGlobals:
  1154.     dc.l    0    
  1155.  
  1156. @start:    
  1157.  
  1158.     movem.l    d0, -(sp)
  1159.     
  1160.     cmp.w    #0x0646, 0x910
  1161.     bne.s    @callOriginalTrap
  1162.     
  1163.     move.l    0x912, d0
  1164.     cmp.l    #0x696e6465, d0
  1165.     bne.s    @callOriginalTrap
  1166.  
  1167.     cmp.b    #'r', 0x916
  1168.     bne.s    @callOriginalTrap
  1169.     
  1170.     link    a6, #0
  1171.     movem.l    registersToSave, -(sp)
  1172.  
  1173.     #ifdef BUILDINGINIT
  1174.     move.l    myGlobals, a4
  1175.     #else
  1176.     move.l    myGlobals, a5
  1177.     #endif
  1178.  
  1179.     jsr        InstallIconServicesPatches
  1180.     jsr        InstallCopyBitsPatch
  1181.  
  1182.     movem.l    (sp)+, registersToSave
  1183.     
  1184.     unlk    a6
  1185.  
  1186. @callOriginalTrap:
  1187.     movem.l    (sp)+, d0
  1188.     
  1189.     move.l    originalPatchAddress, -(sp)
  1190.     
  1191.     rts
  1192. }
  1193.  
  1194. pascal asm void DisposeWindowPatch ( GrafPtr )
  1195. {
  1196.     bra.s    @start
  1197.  
  1198. originalPatchAddress:    
  1199.     dc.l    0
  1200.     
  1201. myGlobals:
  1202.     dc.l    0    
  1203.  
  1204. @start:    
  1205.     
  1206.     link    a6, #0
  1207.     movem.l    registersToSave, -(sp)
  1208.  
  1209.     #ifdef BUILDINGINIT
  1210.     move.l    myGlobals, a4
  1211.     #else
  1212.     move.l    myGlobals, a5
  1213.     #endif
  1214.  
  1215.     move.l     8(a6), -(sp)
  1216.     jsr        DisposeWindowRoutine
  1217.  
  1218.     movem.l    (sp)+, registersToSave
  1219.     
  1220.     unlk    a6
  1221.  
  1222. @callOriginalTrap:
  1223.     
  1224.     move.l    originalPatchAddress, -(sp)
  1225.     
  1226.     rts
  1227. }
  1228.  
  1229. pascal asm void HideWindowPatch ( GrafPtr )
  1230. {
  1231.     bra.s    @start
  1232.  
  1233. originalPatchAddress:    
  1234.     dc.l    0
  1235.     
  1236. myGlobals:
  1237.     dc.l    0    
  1238.  
  1239. @start:    
  1240.     
  1241.     link    a6, #0
  1242.     movem.l    registersToSave, -(sp)
  1243.  
  1244.     #ifdef BUILDINGINIT
  1245.     move.l    myGlobals, a4
  1246.     #else
  1247.     move.l    myGlobals, a5
  1248.     #endif
  1249.  
  1250.     move.l     8(a6), -(sp)
  1251.     jsr        DisposeWindowRoutine
  1252.  
  1253.     movem.l    (sp)+, registersToSave
  1254.     
  1255.     unlk    a6
  1256.  
  1257. @callOriginalTrap:
  1258.     
  1259.     move.l    originalPatchAddress, -(sp)
  1260.     
  1261.     rts
  1262. }
  1263.  
  1264.  
  1265.  
  1266. pascal asm OSErr IconServicesTrapPatch ()
  1267. {
  1268.     bra.s    @start
  1269.  
  1270. originalPatchAddress:    
  1271.     dc.l    0
  1272.     
  1273. myGlobals:
  1274.     dc.l    0    
  1275.  
  1276. @start:    
  1277.  
  1278.     cmp.w    #0x03, d0
  1279.     beq        @GetIconRefFromFileInfoDispatch
  1280.  
  1281.     cmp.w    #0x0e, d0
  1282.     beq        @PlotIconRefDispatch
  1283.  
  1284.     cmp.w    #0x0d, d0
  1285.     beq        @DisposeIconRefDispatch
  1286.  
  1287.     cmp.w    #0x04, d0
  1288.     beq        @GetIconRefFromFolderInfoDispatch
  1289.  
  1290.     cmp.w    #0x02, d0
  1291.     beq        @GetIconRefFromFileDispatch
  1292.  
  1293.     cmp.w    #0x01, d0
  1294.     beq        @NewIconSuiteFromFileDispatch
  1295.  
  1296.     move.l    originalPatchAddress, -(sp)
  1297.     rts
  1298.  
  1299. //    pascal OSErr NewIconSuiteFromFile(const FSSpec *theFile, IconSelectorValue whichIcons, Handle *iconSuite, IconServicesUsageFlags iconServicesUsageFlags)
  1300.  
  1301. @NewIconSuiteFromFileDispatch:
  1302.  
  1303.     link    a6, #0
  1304.     movem.l    registersToSave, -(sp)
  1305.  
  1306.     #ifdef BUILDINGINIT
  1307.     move.l    myGlobals, a4
  1308.     #else
  1309.     move.l    myGlobals, a5
  1310.     #endif
  1311.     
  1312.     clr.w    -(sp)                // space for result
  1313.     move.l    16(a6), -(sp)        //    theFile
  1314.     move.l    16(a6), -(sp)        //    whichIcons
  1315.     move.l    12(a6), -(sp)        //    *iconSuite
  1316.     move.l     8(a6), -(sp)        //    iconServicesUsageFlags
  1317.     
  1318.     jsr        NewIconSuiteFromFilePatch
  1319.  
  1320.     move.w    (sp)+, d0    
  1321.     movem.l    (sp)+, registersToSave
  1322.     
  1323.     unlk    a6
  1324.     
  1325.     move.l    (sp)+, a0
  1326.     add.l    #16, sp
  1327.     move.w    d0, (sp)
  1328.     
  1329.     jmp        (a0)
  1330.  
  1331. //    pascal OSErr GetIconRefFromFile(const FSSpec *theFile, IconRef *iconRef, SInt16 *theLabel)
  1332.  
  1333. @GetIconRefFromFileDispatch:
  1334.  
  1335.     link    a6, #0
  1336.     movem.l    registersToSave, -(sp)
  1337.  
  1338.     #ifdef BUILDINGINIT
  1339.     move.l    myGlobals, a4
  1340.     #else
  1341.     move.l    myGlobals, a5
  1342.     #endif
  1343.     
  1344.     clr.w    -(sp)                // space for result
  1345.     move.l    16(a6), -(sp)        //    *theFile
  1346.     move.l    12(a6), -(sp)        //    *IconRef
  1347.     move.l     8(a6), -(sp)        //    *theLabel
  1348.     
  1349.     jsr        GetIconRefFromFilePatch
  1350.  
  1351.     move.w    (sp)+, d0    
  1352.     movem.l    (sp)+, registersToSave
  1353.     
  1354.     unlk    a6
  1355.     
  1356.     move.l    (sp)+, a0
  1357.     add.l    #12, sp
  1358.     move.w    d0, (sp)
  1359.     
  1360.     jmp        (a0)
  1361.  
  1362. //    pascal OSErr GetIconRefFromFileInfoPatch ( const FSSpec *spec, IconRef *iconRef, OSType creatorCode, OSType fileType, Boolean hasCustomIcon )
  1363.  
  1364. @GetIconRefFromFileInfoDispatch:
  1365.  
  1366.     link    a6, #0
  1367.     movem.l    registersToSave, -(sp)
  1368.  
  1369.     #ifdef BUILDINGINIT
  1370.     move.l    myGlobals, a4
  1371.     #else
  1372.     move.l    myGlobals, a5
  1373.     #endif
  1374.     
  1375.     clr.w    -(sp)                // space for result
  1376.     move.l    22(a6), -(sp)        //    spec
  1377.     move.l    18(a6), -(sp)        //    *iconRef
  1378.     move.l    14(a6), -(sp)        //    creator
  1379.     move.l    10(a6), -(sp)        //    fileType
  1380.     move.w     8(a6), -(sp)        //    boolean hasCustomIcon
  1381.     
  1382.     jsr        GetIconRefFromFileInfoPatch
  1383.  
  1384.     move.w    (sp)+, d0    
  1385.     movem.l    (sp)+, registersToSave
  1386.     
  1387.     unlk    a6
  1388.     
  1389.     move.l    (sp)+, a0
  1390.     add.l    #18, sp
  1391.     move.w    d0, (sp)
  1392.     
  1393.     jmp        (a0)
  1394.  
  1395. //    extern pascal OSErr GetIconRefFromFolderInfo(SInt16 vRefNum, SInt32 folderID, IconRef *iconRef, OSType fileType, Boolean hasCustomIcon)
  1396.  
  1397. @GetIconRefFromFolderInfoDispatch:
  1398.  
  1399.     link    a6, #0
  1400.     movem.l    registersToSave, -(sp)
  1401.     
  1402.     #ifdef BUILDINGINIT
  1403.     move.l    myGlobals, a4
  1404.     #else
  1405.     move.l    myGlobals, a5
  1406.     #endif
  1407.     
  1408.     clr.w    -(sp)                // space for result
  1409.     move.w    22(a6), -(sp)        //    vRefNum
  1410.     move.l    18(a6), -(sp)        //    folderID
  1411.     move.l    14(a6), -(sp)        //    *iconRef
  1412.     move.l    10(a6), -(sp)        //    fileType
  1413.     move.w     8(a6), -(sp)        //    boolean hasCustomIcon
  1414.  
  1415.     jsr        GetIconRefFromFolderInfoPatch
  1416.  
  1417.     move.w    (sp)+, d0    
  1418.     movem.l    (sp)+, registersToSave
  1419.     
  1420.     unlk    a6
  1421.     
  1422.     move.l    (sp)+, a0
  1423.     add.l    #16, sp
  1424.     move.w    d0, (sp)
  1425.     
  1426.     jmp        (a0)
  1427.  
  1428. //    pascal OSErr PlotIconRef (const Rect *theRect, IconAlignmentType align,
  1429. //                                IconTransformType transform, IconRef iconRef )
  1430. //
  1431. //        4    return addr
  1432. //        8    theIconSuite
  1433. //        12    transform
  1434. //        14    align
  1435. //        16    theRect
  1436. //        20    result
  1437. //
  1438. @PlotIconRefDispatch:
  1439.  
  1440.     link    a6, #0
  1441.     movem.l    registersToSave, -(sp)
  1442.  
  1443.     #ifdef BUILDINGINIT
  1444.     move.l    myGlobals, a4
  1445.     #else
  1446.     move.l    myGlobals, a5
  1447.     #endif
  1448.  
  1449.     clr.w    -(sp)                // space for result
  1450.     move.l    20(a6), -(sp)        //    rect
  1451.     move.w    18(a6), -(sp)        //    align
  1452.     move.w    16(a6), -(sp)        //    transform
  1453.     move.l    12(a6), -(sp)        //    usageFlags
  1454.     move.l     8(a6), -(sp)        //    iconRef
  1455.     
  1456.     jsr        PlotIconRefPatch
  1457.  
  1458.     move.w    (sp)+, d0    
  1459.     movem.l    (sp)+, registersToSave
  1460.     
  1461.     unlk    a6
  1462.     
  1463.     move.l    (sp)+, a0
  1464.     add.l    #16, sp
  1465.     move.w    d0, (sp)
  1466.     
  1467.     jmp        (a0)
  1468.  
  1469. @DisposeIconRefDispatch:
  1470.  
  1471.     // _Debugger
  1472.     
  1473.     link    a6, #0
  1474.     movem.l    registersToSave, -(sp)
  1475.  
  1476.     #ifdef BUILDINGINIT
  1477.     move.l    myGlobals, a4
  1478.     #else
  1479.     move.l    myGlobals, a5
  1480.     #endif
  1481.  
  1482.     clr.w    -(sp)                // space for result
  1483.     move.l     8(a6), -(sp)        //    Handle: iconSuiteH
  1484.     
  1485.     jsr        DisposeIconRefPatch
  1486.  
  1487.     move.w    (sp)+, d0    
  1488.     movem.l    (sp)+, registersToSave
  1489.     
  1490.     unlk    a6
  1491.     
  1492.     move.l    (sp)+, a0
  1493.     add.l    #4, sp
  1494.     move.w    d0, (sp)
  1495.     
  1496.     jmp        (a0)
  1497. }
  1498.  
  1499. //    ============================================================================================
  1500.  
  1501. asm pascal void jGNEFilter ( )
  1502. {
  1503.     bra.s    @start
  1504.     
  1505. nextGNEFilterRoutine:    
  1506.     dc.l    0
  1507.  
  1508. myGlobals:
  1509.     dc.l    0    
  1510.     
  1511.     //    the EventRecord is pointed to by a1
  1512.     //    We return a true/false value in d0 as to whether to handle the event.
  1513.  
  1514. @start:
  1515.     movem.l    registersToSave, -(sp)
  1516.     
  1517.     #ifdef BUILDINGINIT
  1518.     move.l    myGlobals, a4
  1519.     #else
  1520.     move.l    myGlobals, a5
  1521.     #endif
  1522.  
  1523.     clr.w    -(sp)
  1524.     move.l    a1, -(sp)
  1525.     jsr        MyGNEFilterRoutine
  1526.     move.w    (sp)+, d0
  1527.  
  1528.     movem.l    (sp)+, registersToSave
  1529.  
  1530.     move.l    nextGNEFilterRoutine, a0
  1531.     cmp.l    #0,    a0
  1532.     beq.s    @1
  1533.     
  1534.     move.l    a0, -(sp)
  1535. @1:
  1536.     rts
  1537. }
  1538.  
  1539. //    ============================================================================================
  1540.  
  1541. asm pascal void CopyBitsPatch ( BitMap* srcBits, BitMap* destBits,
  1542.                               const Rect* srcRect, const Rect* destRect,
  1543.                               short mode, RgnHandle maskRgn )
  1544. {
  1545.     bra.s    @start
  1546.     
  1547. originalPatchAddress:    
  1548.     dc.l    0
  1549.     
  1550. myGlobals:
  1551.     dc.l    0    
  1552.  
  1553.     //    the EventRecord is pointed to by a1
  1554.     //    We return a true/false value in d0 as to whether to handle the event.
  1555.  
  1556. @start:
  1557.     link    a6, #0
  1558.     movem.l    registersToSave, -(sp)
  1559.  
  1560.     #ifdef BUILDINGINIT
  1561.     move.l    myGlobals, a4
  1562.     #else
  1563.     move.l    myGlobals, a5
  1564.     #endif
  1565.  
  1566.     move.l    26(a6), -(sp)        //    srcBits
  1567.     move.l    22(a6), -(sp)        //    destBits
  1568.     move.l    18(a6), -(sp)        //    srcRect
  1569.     move.l    14(a6), -(sp)        //    destRect
  1570.     move.w    12(a6), -(sp)        //    mode
  1571.     move.l     8(a6), -(sp)        //    maskRgn
  1572.  
  1573.     jsr        CopyBitsRoutine
  1574.     
  1575.     movem.l    originalPatchAddress, a0
  1576.     movem.l    (sp)+, registersToSave
  1577.     
  1578.     unlk    a6
  1579.         
  1580.     jmp        (a0)
  1581. }
  1582.  
  1583.  
  1584. //    ============================================================================================
  1585.  
  1586. asm pascal void QDExtensionsPatch (  )
  1587. {
  1588.     bra.s    @start
  1589.     
  1590. originalPatchAddress:    
  1591.     dc.l    0
  1592.     
  1593. myGlobals:
  1594.     dc.l    0    
  1595.  
  1596. //    
  1597. @start:
  1598.  
  1599.     cmp.w    #0x0000, d0
  1600.     beq.s    @NewGWorldPatch
  1601.  
  1602.     cmp.w    #0x0004, d0
  1603.     beq.s    @DisposeGWorld
  1604.     
  1605.     cmp.w    #0x0003, d0
  1606.     beq.s    @UpdateGWorld
  1607.     
  1608.     move.l    originalPatchAddress, -(sp)
  1609.     rts
  1610.  
  1611. @NewGWorldPatch:
  1612.     
  1613.     link    a6, #0
  1614.     movem.l    registersToSave, -(sp)
  1615.  
  1616.     #ifdef BUILDINGINIT
  1617.     move.l    myGlobals, a4
  1618.     #else
  1619.     move.l    myGlobals, a5
  1620.     #endif
  1621.  
  1622.     clr.w    -(sp)
  1623.     move.l    26(a6), -(sp)        //    srcBits
  1624.     move.w    24(a6), -(sp)        //    destBits
  1625.     move.l    20(a6), -(sp)        //    srcRect
  1626.     move.l    16(a6), -(sp)        //    destRect
  1627.     move.l    12(a6), -(sp)        //    mode
  1628.     move.l     8(a6), -(sp)        //    maskRgn
  1629.  
  1630.     jsr        NewGWorldRoutine
  1631.     move.w    (sp)+, d0
  1632.     
  1633.     movem.l    (sp)+, registersToSave
  1634.     
  1635.     unlk    a6
  1636.  
  1637.     move.l    (sp)+, a0
  1638.     add.l    #22, sp
  1639.     move.w    d0, (sp)
  1640.     
  1641.     jmp        (a0)
  1642.     
  1643. //    void DisposeGWorld ( GWorldPtr theGWorld )
  1644. @DisposeGWorld:
  1645.     
  1646.     link    a6, #0
  1647.     movem.l    registersToSave, -(sp)
  1648.  
  1649.     #ifdef BUILDINGINIT
  1650.     move.l    myGlobals, a4
  1651.     #else
  1652.     move.l    myGlobals, a5
  1653.     #endif
  1654.  
  1655.     move.l     8(a6), -(sp)        //    maskRgn
  1656.  
  1657.     jsr        DisposeGWorldRoutine
  1658.         
  1659.     movem.l    (sp)+, registersToSave
  1660.     
  1661.     unlk    a6
  1662.  
  1663.     move.l    (sp)+, a0
  1664.     add.l    #4, sp
  1665.     
  1666.     jmp        (a0)
  1667.     
  1668. @UpdateGWorld:
  1669.     link    a6, #0
  1670.     movem.l    registersToSave, -(sp)
  1671.  
  1672.     #ifdef BUILDINGINIT
  1673.     move.l    myGlobals, a4
  1674.     #else
  1675.     move.l    myGlobals, a5
  1676.     #endif
  1677.  
  1678.     clr.w    -(sp)
  1679.     move.l    26(a6), -(sp)        //    srcBits
  1680.     move.w    24(a6), -(sp)        //    destBits
  1681.     move.l    20(a6), -(sp)        //    srcRect
  1682.     move.l    16(a6), -(sp)        //    destRect
  1683.     move.l    12(a6), -(sp)        //    mode
  1684.     move.l     8(a6), -(sp)        //    maskRgn
  1685.  
  1686.     jsr        UpdateGWorldRoutine
  1687.     move.w    (sp)+, d0
  1688.     
  1689.     movem.l    (sp)+, registersToSave
  1690.     
  1691.     unlk    a6
  1692.  
  1693.     move.l    (sp)+, a0
  1694.     add.l    #22, sp
  1695.     move.w    d0, (sp)
  1696.     
  1697.     jmp        (a0)
  1698. }
  1699.